package com.soul.server.controller;

import com.soul.model.dto.QuestionDto;
import com.soul.server.server.TestSoulService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author mdoya
 * @version 1.0
 * @description: 灵魂测试控制层
 */
@Slf4j
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     *  测灵魂-提交问卷
     * @param answers Map类型 作答
     * @return 最新报告id
     */
    @PostMapping
    public ResponseEntity addSoul(@RequestBody Map<String, List<QuestionDto>> answers){
        log.debug("测灵魂-提交问卷: {}",answers);
        List<QuestionDto> questionDtoList = answers.get("answers"); // 试题编号、选项编号
        return ResponseEntity.ok(testSoulService.addSoul(questionDtoList)); // reportId报告id
    }

    /**
     *  测灵魂-查看结果
     * @param reportId 报告id
     * @return TestSoulVo
     */
    @GetMapping("/report/{id}")
    public ResponseEntity findReportResult(@PathVariable("id") String reportId){
        log.debug("测灵魂-最新报告id: {}",reportId);
        return ResponseEntity.ok(testSoulService.findReportResult(reportId));
    }

    /**
     *  测灵魂-问卷列表
     * @return  List<SoulVo>
     */
    @GetMapping
    public ResponseEntity testSoul(){
        log.debug("测灵魂-问卷列表");
        return ResponseEntity.ok(testSoulService.testSoul());
    }
}
